<template>
    <!-- 对话框表单 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="baTable.form.operate ? true : false"
        width="600px"
        @close="baTable.toggleForm"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :disabled="true"
                    :rules="rules"
                >
                <FormItem :label="t('xCorpsq.CORP')" type="string" v-model="baTable.form.items!.CORP" prop="CORP" :input-attr="{ placeholder: t('Please input field', { field: t('xCorpsq.CORP') }) }" />
                <FormItem :label="t('xCorpsq.CORPNAME')" type="string" v-model="baTable.form.items!.CORPNAME" prop="CORPNAME" :input-attr="{ placeholder: t('Please input field', { field: t('xCorpsq.CORPNAME') }) }" />
                <FormItem :label="t('xCorpsq.ENAME')" type="string" v-model="baTable.form.items!.ENAME" prop="ENAME" :input-attr="{ placeholder: t('Please input field', { field: t('xCorpsq.ENAME') }) }" />
                <!-- <FormItem :label="t('xCorpsq.DEPT')" type="string" v-model="baTable.form.items!.DEPT" prop="DEPT" :input-attr="{ placeholder: t('Please input field', { field: t('xCorpsq.DEPT') }) }" /> -->
                <FormItem :label="t('xCorpsq.OP')" type="string" v-model="baTable.form.items!.OP" prop="OP" :input-attr="{ placeholder: t('Please input field', { field: t('xCorpsq.OP') }) }" />
                <FormItem :label="t('xCorpsq.OPTIME')" type="datetime" v-model="baTable.form.items!.OPTIME" prop="OPTIME" :input-attr="{ placeholder: t('Please select field', { field: t('xCorpsq.OPTIME') }) }" />
                <FormItem :label="t('xCorpsq.SQTYPE')" type="string" v-model="baTable.form.items!.SQTYPE" prop="SQTYPE" :input-attr="{ placeholder: t('Please input field', { field: t('xCorpsq.SQTYPE') }) }" />
                <FormItem :label="'修改内容'" type="textarea" v-model="baTable.form.items!.REMARK" prop="REMARK" :input-attr="{ placeholder: t('Please input field', { field: t('xCorpsq.REMARK') }) }" />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button type="primary" v-if="route.name=='corplib/supplier/approve'&&baTable.form.items!.statuss=='待审批'" @click="toApproval('approve')">审批</el-button>
                <el-button type="primary" v-if="route.name=='corplib/supplier'&&baTable.form.items!.statuss=='未发起'" @click="handleTj()">提交审批</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import { ElForm, ElMessage, FormItemRule } from 'element-plus'
import { buildValidatorData } from '/@/utils/validate'
import { useApprovalInfo } from '/@/stores/approvalDialog'
import { useRoute } from 'vue-router'
import createAxios from '/@/utils/axios'

const formRef = ref<InstanceType<typeof ElForm>>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    OPTIME: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('xCorpsq.OPTIME') })})],
})

const route = useRoute()
console.log(route.name)
const handleTj = ()=>{
  createAxios({
    url:'admin/Corplib/tj',
    data:{
            ...baTable.form.items,
            bizno:baTable.form.items!.BIZNO
        },
        method:'post'
  }).then(()=>{
    ElMessage.success('提交成功')
    baTable.toggleForm()
    baTable.getIndex()
  })
}

//查看审批流
const approvalInfo = useApprovalInfo()

const toApproval = (type:string)=> {
    approvalInfo.setData({
        bizno:baTable.form.items!.BIZNO,
        type,
        flowname:'',
        callback:()=>{
            baTable.getIndex()
            baTable.toggleForm()
        }
    })
    approvalInfo.setDialogShow(true)
}


</script>

<style scoped lang="scss"></style>
